<html lang="en">
<head>
    <title>目的地主题管理</title>
    <#include "../common/header.ftl">
    <#--<link rel="stylesheet" href="/js/plugins/treeview/bootstrap-treeview.min.css" type="text/css" />-->
    <#--<script type="text/javascript" src="/js/plugins/treeview/bootstrap-treeview.min.js"></script>-->
    <link type="text/css" rel="stylesheet" href="/js/plugins/uploadifive/uploadifive.css" />
    <script type="text/javascript" src="/js/plugins/uploadifive/jquery.uploadifive.min.js"></script>
    <style>
        .textarea1{
            width: 100%;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            //编辑/添加
            $(".inputBtn").click(function () {
                //弹出模态框
                $("#editModal").modal("show");

//                $("#treeview").html("");
                //数据复原
                $("#editForm").clearForm(true);
                //目的地回显数据
                //判断时添加还是编辑
                var marker = $(this).data("marker");
                if (marker == "input"){
                    var data = $(this).data("json");
                    if(data){
                        $("#parentId_input").val(data.id);
                        $("input[name='deep']").val(data.deep + 1);
                        $("#parentName").val(data.name);
                    }
                }else {
                    var data = $(this).data("json");
                    if(data){
                        $("#parentId_input").val(data.parentId);
                        $("input[name='deep']").val(data.deep);
                        $("input[name='id']").val(data.id);
                        $("#parentName").val(data.parentName);
                        $("input[name='name']").val(data.name);
                        $("select[name='state']").val(data.state);
                        $("input[name='sequence']").val(data.sequence);
                        $("#coverUrl").val(data.coverUrl);
                        $("#imgUrl").attr("src",data.coverUrl);
                    }
                }
            })
            
            $(".submitBtn").click(function () {
                //模态框表单提交
                $("#editForm").ajaxSubmit(function (data) {
                    if(data.success){
                        window.location.reload();
                    }else{
                        $.messager.alert("温馨提示", data.msg)
                    }
                })
            })

            //查询
            $(".clickBtn").click(function () {
                var parentId = $(this).data("parentid");
                $("#parentId").val(parentId);
                $("#currentPage").val(1);
                $("#searchForm").submit();
            })

            //图片上传
            $('.imgBtn').uploadifive({
                'auto' : true,  //自动提交
                'uploadScript' : '/uploadImg',  //图片上传过来处理路径（接收）
                buttonClass:"btn-link", //按钮的样式
                'fileObjName' : 'pic',  //图片文件上传之后，在springmVC映射方法接收到额参数名
                'buttonText' : '浏览...',//按钮上面的文字
                'fileType' : 'image',//指定上传的图片
                'multi' : false,//是否为多文件上传，此处设置单文件
                'fileSizeLimit'   : 5242880,//文件上传大小
                'removeCompleted' : true, //取消上传完成提示
                'uploadLimit' : 1,  //上传文件的个数
                //'queueSizeLimit'  : 10,   //文件上传等待队列大小
                'overrideEvents': ['onDialogClose', 'onError'],    //onDialogClose 取消自带的错误提示
                'onUploadComplete' : function(file, data) {     //文件上传成功后，做什么动作
                    //data 请求方法处理完之后，传回来的数据，约定：图片的路径（url）
                    $("#imgUrl").attr("src" , "/" + data);
                    $("#coverUrl").val("/" + data); //IP：端口 /斜杠

                },
                onFallback : function() {       //失败时候做的操作
                    $.messager.alert("温馨提示","该浏览器无法使用!");
                }
            });
        })
    </script>
</head>
<body>
<#--上传文件的工具框-->
<!--左侧菜单回显变量设置-->
<#assign currentMenu="destinationTheme">

<div class="container-fluid " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-2">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-10">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">目的地主题管理</h1>
                </div>
            </div>
            <#setting number_format="#">
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/destinationTheme/list" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <input type="hidden" name="parentId" id="parentId" value="${qo.parentId!}">
                <div class="form-group">
                    <label for="keyword">关键字:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}" placeholder="请输入名称">
                </div>
                <div class="form-group">
                </div>
                <button type="button" class="btn btn-primary clickBtn" data-parentid="${qo.parentId!}"><span class="glyphicon glyphicon-search"></span>查询</button>
                <a class="btn btn-success inputBtn" href="javascript:;" data-json='${(parentTheme.jsonString)!}' data-marker="input">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>

               <h4>
                    当前位置: <a href="javascript:;" class="clickBtn">根</a>
                <#list toasts as t>
                         >> <a href="javascript:;" data-parentid="${(t.id)!}" class="clickBtn">${(t.name)!}</a>
                </#list>
                </h4>

            </form>

            <table class="table table-striped table-hover" >
                <thead>
                    <tr>
                        <th>序号</th>
                        <th>名称</th>
                        <th>封面</th>
                        <th>上级</th>
                        <th>显示优先级</th>
                        <th>显示状态</th>
                        <th>操作</th>
                    </tr>
                </thead>
               <#list pageInfo.list as entity>
                   <tr>
                       <td>${entity_index+1}</td>
                       <td><a href="/destinationTheme/list?parentId=${entity.id}">${entity.name!}</a></td>
                       <td><img src="${entity.coverUrl}" width="100px"/> </td>
                       <td>${(entity.parentTheme.name)!"顶级"}</td>
                       <td>${(entity.sequence)!}</td>
                       <td>${entity.state}</td>
                       <td>
                           <a class="btn btn-info btn-xs inputBtn" href="javascript:;" data-json='${entity.jsonString}' data-marker="edit">
                               <span class="glyphicon glyphicon-edit"></span> 编辑
                           </a>

                           <a href="javascript:;" class="btn btn-danger btn-xs deleteBtn"
                              data-url="/destination/delete?id=${entity.id}">
                               <span class="glyphicon glyphicon-trash"></span> 删除
                           </a>
                       </td>
                   </tr>
               </#list>
            </table>
            <#--分页-->
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>

<#--目的地编辑模态框-->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span> </button>
                <h4 class="modal-title">目的地主题</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/destinationTheme/saveOrUpdate" method="post" id="editForm">
                    <input type="hidden" value="" name="parentTheme.id" id="parentId_input">
                    <input type="hidden" value="" name="deep">
                    <input type="hidden" value="" name="id">

                    <div class="form-group">
                        <label  class="col-sm-3 control-label">父级主题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" value="" id="parentName" name="parentTheme.name" readonly="readonly">
                        </div>
                    </div>

                    <div class="form-group">
                        <label  class="col-sm-3 control-label">名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="name" name="name"  placeholder="请输入主题名称">
                        </div>
                    </div>

                    <div class="form-group">
                        <label  class="col-sm-3 control-label">发布状态：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="state" name="state">
                                <option value="1">正常</option>
                                <option value="0">禁止发布</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label  class="col-sm-3 control-label">显示优先级：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sequence" placeholder="请输入优先级" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label  class="col-sm-3 control-label">目的地主题封面：</label>
                        <div class="col-sm-6">
                            <input type="hidden"  class="form-control" id="coverUrl"  name="coverUrl" value="" >
                            <img src="/images/default.jpg" width="100px" id="imgUrl">
                            <button type="button" class="imgBtn">浏览</button>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary submitBtn" >保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>